<template>
  <div>
    <el-select
      style="display: block"
      :size="size"
      v-model="value"
      placeholder="请选择客户身份"
      @change="changeValue"
      clearable
      @clear="changeValue"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
  </div>
</template>

<script>
import { isNotNull } from "@/util/common-util";

export default {
  name: "customer-type-select",
  props: {
    initValue: {
      type: Object,
      default: null,
    },
    size: {
      type: String,
      default: "small",
    },
  },
  data() {
    return {
      options: [],
      value: "",
    };
  },
  created() {
    this.initOptions(() => {
      if (isNotNull(this.initValue)) {
        this.value = this.initValue;
      }
    });
  },
  methods: {
    // 0-普通车主;1--车队成员'
    initOptions(success) {
      this.options = [
        {
          label: "全部",
          value: null,
        },
        {
          label: "车队成员",
          value: 1,
        },
        {
          label: "普通车主",
          value: 0,
        },
      ];
      success && success();
    },
    changeValue() {
      this.$emit("change", this.value);
    },
  },
};
</script>

<style lang="scss" scoped></style>
